package cn.yunhe.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.yunhe.entity.Drug;
import cn.yunhe.entity.Supp;
import cn.yunhe.service.SuppService;

@Controller
public class SuppController {
	@Autowired
	private SuppService suppService;

	@RequestMapping("/selectSupp")
	public String selectDrud(HttpServletRequest request) {
		List<Supp> supp = suppService.selectSupp();
		request.setAttribute("supplist", supp);
		return "Supp";
	}

	@RequestMapping("/selectMoHuSupp")
	public String selectMoHuSupp(HttpServletRequest request, String pname) {
		System.out.println(pname);
		List<Supp> supp1 = suppService.selectMoHuSupp(pname);
		request.setAttribute("supplist", supp1);
		return "SuppSelectMoHo";
	}

	@RequestMapping("/selectSuppAndTypeAndDrug")
	public String selectSuppAndTypeAndDrug(HttpServletRequest request, String pname) {
		System.out.println(pname);
		
		List<Drug> Drug = suppService.selectSuppAndTypeAndDrug(pname);
		request.setAttribute("Drug", Drug);
		return "SelectSuppAndTypeAndDrug";
	}

	@RequestMapping("/insertSupp")
	public String insertSupp(HttpServletRequest request, Supp supp) {
		System.out.println("111111111111");
		int num = suppService.insertSupp(new Supp(supp.getPname(), 1, supp.getPphone(), supp.getPaddre()));
		System.out.println(num);
		List<Supp> supp1 = suppService.selectSupp();
		request.setAttribute("supplist", supp1);
		return "redirect:selectSupp.do";
	}

	@RequestMapping("/updateSupp")
	public String updateSupp(HttpServletRequest request, Supp supp) {
		int num = suppService.updateSupp(new Supp(supp.getPid(), supp.getPname(), supp.getPphone(), supp.getPaddre()));
		List<Supp> supp1 = suppService.selectSupp();
		request.setAttribute("supplist", supp1);
		return "redirect:selectSupp.do";
	}
	@RequestMapping("/selectSupp1")
	public String selectDrud1(HttpServletRequest request) {
		List<Supp> supp = suppService.selectSupp();
		request.setAttribute("supplist", supp);
		return "SuppUpdatePstate";
	}
	
	
	@RequestMapping("/updatePstateSupp")
	public String updatePstateSupp(HttpServletRequest request, Supp supp) {
		int num = suppService.updatePstateSupp(new Supp(supp.getPname(),supp.getPstate()));
		List<Supp> supp1 = suppService.selectSupp();
		request.setAttribute("supplist", supp1);
		return "redirect:selectSupp.do";
	}
	public SuppService getSuppService() {
		return suppService;
	}

	public void setSuppService(SuppService suppService) {
		this.suppService = suppService;
	}
}
